package club.kingyin.kyblogprocore.dao;

import club.kingyin.commons.entity.core.Document;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;

/**
 * (Document)表数据库访问层
 *
 * @author makejava
 * @since 2022-02-16 18:22:14
 */
public interface DocumentDao extends BaseMapper<Document> {

    @Select("select ifnull(sum(views),0) from document where userid = #{id}")
    int sumViewByUserId(int id);

    @Select("SELECT title FROM document B JOIN ( SELECT CEIL( MAX( ID ) * RAND( ) ) AS ID FROM document ) AS m ON B.ID >= m.ID LIMIT 1")
    String randomOneTitle();
}

